package com.godpaper.as9.commands
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	import com.godpaper.as9.bussiness.delegates.PhotoDelegate;
	import com.godpaper.as9.constants.SearchModeList;
	import com.godpaper.as9.events.FindPhotosByNameEvent;
	import com.godpaper.as9.events.FindPhotosByTagEvent;
	import com.godpaper.as9.events.TryDeletePhotoEvent;
	import com.godpaper.as9.model.PhotoModelLocator;
	import com.godpaper.as9.model.UserModelLocator;
	
	import mx.rpc.IResponder;

	public class TryDeletePhotoCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:PhotoDelegate;
		private var tryDeletePhotoEvent:TryDeletePhotoEvent;
		private var photoModel:PhotoModelLocator = PhotoModelLocator.getInstance();
		[Bindable]
		private var userModel:UserModelLocator = UserModelLocator.getInstance();
		public function TryDeletePhotoCommand()
		{
			super();
			delegate = new PhotoDelegate(this);
		}
		
		override public function execute(event:CairngormEvent):void
		{
			tryDeletePhotoEvent = TryDeletePhotoEvent(event);
			delegate.delete_(tryDeletePhotoEvent.pno);
		}
		
		override public function result(data:Object):void
		{
//			trace(data.result.info);
			if(data.result.info=="success")
			{
				switch(userModel.searchBehavior.mode)
				{
					case SearchModeList.MODE_BY_NAME:
						CairngormEventDispatcher.getInstance().dispatchEvent(new FindPhotosByNameEvent(userModel.searchBehavior.key));
						break;
					case SearchModeList.MODE_BY_TAG:
						CairngormEventDispatcher.getInstance().dispatchEvent(new FindPhotosByTagEvent(userModel.searchBehavior.key));
						break;	
					default:
						break;	
				}
				
			}
		}
		
		
	}
}